package com.mine.modules.vm.controller;


import com.mine.common.domain.vo.Result;
import com.mine.modules.sys.domain.dto.RoleDto;
import com.mine.modules.vm.domain.dto.*;
import com.mine.modules.vm.domain.query.CountElementQuery;
import com.mine.modules.vm.domain.query.LayerQuery;
import com.mine.modules.vm.service.IVmLayerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 场景图层管理
 * </p>
 *
 * @author author
 * @since 2024-10-15
 */
@Slf4j
@Api(tags = "场景图层管理")
@RestController
@RequestMapping("/vm/layer")
@RequiredArgsConstructor
public class VmLayerController {

    private final IVmLayerService vmLayerService;

    @ApiOperation("图层树形列表")
    @RequestMapping(value = "/listAll", method = RequestMethod.GET)
    public Result<?> listAll(LayerQuery layerQuery) {
        return vmLayerService.listAll(layerQuery);
    }

    @ApiOperation("图层列表查询-异步")
    @RequestMapping(value = "/listByParentId", method = RequestMethod.GET)
    public Result<?> listByParentId(LayerQuery layerQuery) {
        return vmLayerService.listByParentId(layerQuery);
    }

    @ApiOperation("token查询菜单图层（带权限过滤）")
    @RequestMapping(value = "/getMenuLayerByToken", method = RequestMethod.GET)
    public Result<?> getMenuLayerByToken(LayerQuery layerQuery) {
        return vmLayerService.getMenuLayerByToken(layerQuery);
    }

    @ApiOperation("token查询菜单图层（分级查询）")
    @RequestMapping(value = "/getMenuLayerListByToken", method = RequestMethod.GET)
    public Result<?> getMenuLayerListByToken(LayerQuery layerQuery) {
        return vmLayerService.getMenuLayerListByToken(layerQuery);
    }

    @ApiOperation("添加或修改图层")
    @PostMapping(value = "/addOrEdit")
    public Result<?> addOrEdit(VmLayerDto layerDto) {
        return vmLayerService.addOrEdit(layerDto);
    }

    @ApiOperation("删除图层")
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
        return vmLayerService.delete(id);
    }

    @ApiOperation("批量删除图层")
    @RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
    public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        return vmLayerService.deleteBatch(ids);
    }

    @ApiOperation("查询角色授权")
    @RequestMapping(value = "/queryRoleLayer", method = RequestMethod.GET)
    public Result<List<String>> queryRoleLayer(@RequestParam(name = "roleId", required = true) String roleId) {
        return vmLayerService.queryRoleLayer(roleId);
    }

    @ApiOperation("保存角色授权")
    @RequestMapping(value = "/saveRoleLayer", method = RequestMethod.POST)
    public Result<?> saveRoleLayer(RoleDto roleDto) {
        return vmLayerService.saveRoleLayer(roleDto);
    }

    @ApiOperation("查询菜单与图层绑定")
    @RequestMapping(value = "/queryMenuLayer", method = RequestMethod.GET)
    public Result<List<String>> queryMenuLayer(@RequestParam(name = "menuId", required = true) String menuId) {
        return vmLayerService.queryMenuLayer(menuId);
    }

    @ApiOperation("保存菜单与图层绑定")
    @RequestMapping(value = "/saveMenuLayer", method = RequestMethod.POST)
    public Result<?> saveMenuLayer(MenuLayerDto menuLayerDto) {
        return vmLayerService.saveMenuLayer(menuLayerDto);
    }

    @ApiOperation("批量添加图元")
    @RequestMapping(value = "/batchAddElement", method = RequestMethod.POST)
    public Result<?> batchAddElement(BatchAddElementDto batchAddElementDto) throws ClassNotFoundException {
        return vmLayerService.batchAddElement(batchAddElementDto);
    }

    @ApiOperation("批量删除图元")
    @RequestMapping(value = "/batchDeleteElement", method = RequestMethod.POST)
    public Result<?> batchDeleteElement(BatchDeleteElementDto batchDeleteElementDto) {
        return vmLayerService.batchDeleteElement(batchDeleteElementDto);
    }

    @ApiOperation("通过图层Id查图元")
    @RequestMapping(value = "/elementListByLayerId", method = RequestMethod.POST)
    public Result<?> elementListByLayerId(ElementByLayerDto elementByLayerDto) {
        return vmLayerService.elementListByLayerId(elementByLayerDto);
    }

    @ApiOperation("图层-绑定场景图层")
    @RequestMapping(value = "/bindSceneLayer", method = RequestMethod.POST)
    public Result<?> bindSceneLayer(@RequestParam(name = "layerId", required = true) String layerId,
                                    @RequestParam(name = "sceneLayerId", required = false) String sceneLayerId) {
        return vmLayerService.bindSceneLayer(layerId, sceneLayerId);
    }

    @ApiOperation("图层-绑定点位图层")
    @RequestMapping(value = "/bindPointLayer", method = RequestMethod.POST)
    public Result<?> bindPointLayer(@RequestParam(name = "layerId", required = true) String layerId,
                                    @RequestParam(name = "pointLayerId", required = false) String pointLayerId) {
        return vmLayerService.bindPointLayer(layerId, pointLayerId);
    }

    @ApiOperation("图元数量统计")
    @RequestMapping(value = "/getCountByLayerId", method = RequestMethod.GET)
    public Result<?> getCountByLayerId(CountElementQuery countElementQuery) {
        return vmLayerService.getCountByLayerId(countElementQuery);
    }

    @ApiOperation("复制图层")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sourceLayerId", value = "源图层id",required = true),
            @ApiImplicitParam(name = "targetLayerId", value = "目标父id",required = false)
    })
    @RequestMapping(value = "/copyLayer", method = RequestMethod.POST)
    public Result<?> copyLayer(@RequestParam String sourceLayerId, @RequestParam(required = false) String targetLayerId) {
        return vmLayerService.copyLayer(sourceLayerId, targetLayerId);
    }

}
